use sea_orm_migration::prelude::*;

#[derive(DeriveMigrationName)]
pub struct Migration;

#[async_trait::async_trait]
impl MigrationTrait for Migration {
    async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
        manager
            .create_table(
                Table::create()
                    .table(Template::Table)
                    .if_not_exists()
                    .col( ColumnDef::new(Template::Id).integer().not_null().auto_increment().primary_key().comment("id") )
                    .col( ColumnDef::new(Template::Name).string_len(30).not_null().unique_key().comment("名称") )
                    .col( ColumnDef::new(Template::NameEn).string_len(30).not_null().unique_key().comment("英文名称") )
                    .col( ColumnDef::new(Template::Content).blob().not_null().comment("模板内容") )
                    .col( ColumnDef::new(Template::ContentUnion).blob().comment("模板内容") )
                    .col( ColumnDef::new(Template::Type).string_len(20).not_null().comment("模板类型") )
                    .col( ColumnDef::new(Template::Level).small_integer().not_null().default(0).comment("排序") )
                    // 固定字段
                    .col( ColumnDef::new(Template::CreateUser).integer().not_null().comment("创建人") )
                    .col( ColumnDef::new(Template::UpdateUser).integer().comment("修改人") )
                    .col( ColumnDef::new(Template::CreateTime).timestamp().default(Expr::current_timestamp()).comment("创建时间") )
                    .col( ColumnDef::new(Template::UpdateTime).timestamp().default(Expr::current_timestamp()).extra("on update current_timestamp").comment("更新时间") )
                    .to_owned(),
            )
            .await
    }

    async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
        manager.drop_table(Table::drop().table(Template::Table).to_owned()).await
    }
}
#[derive(DeriveIden)]
enum Template {
    Table,
    Id,
    Name,
    NameEn,
    Content,
    ContentUnion,
    Type,
    Level,
    CreateUser,
    UpdateUser,
    CreateTime,
    UpdateTime,
}